home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
182_01
/
bbsc.c
< prev
next >
Wrap
Text File
|
1990-07-30
|
29KB
|
1,132 lines
/*
bbsc.c
BBS (Bulletin Board System) written in UNIX SYSTEM-III "C".
Support files needed:
bbscdef.h
bbscport.o or bbscport.c
bbsclock.o or bbsclock.c
bbscfile.o or bbscfile.c
bbscmisc.o or bbscmisc.c
Mike Kelly
03/09/83 v1.0 written
07/07/83 v1.0 updated
*/
#define MAINMOD 1
#include "bbscdef.h"
#define LASTDATE " 02/07/84 "
#define PGMNAME "BBSc "
#define VERSION " 1.1 "
main()
{
int i;
/*
* init global variables
*/
debug = FALSE;
statcnt = 0;
xpert = FALSE;
active = TRUE;
w_fname[0] = '\0';
w_lname[0] = '\0';
strcpy(w_password,"MPK0");
u_fname[0] = '\0';
u_lname[0] = '\0';
strcpy(u_password,"MPK0");
u_time1[0] = '\0';
u_date1[0] = '\0';
u_time2[0] = '\0';
u_date2[0] = '\0';
u_city[0] = '\0';
mm[0] = '\0';
dd[0] = '\0';
yy[0] = '\0';
month[0] = '\0';
day[0] = '\0';
year[0] = '\0';
date[0] = '\0';
week[0] = '\0';
ttime[0] = '\0';
strcpy(msg_delete,"0");
msg_no[0] = '\0';
msg_date[0] = '\0';
msg_date[0] = '\0';
msg_time[0] = '\0';
msg_to[0] = '\0';
msg_from[0] = '\0';
msg_pass[0] = '\0';
msg_subject[0] = '\0';
msg_text[0] = '\0';
stop_that = FALSE;
/* get date and time from the clock */
gettime(ttime);
getdate(mm,dd,yy,month,day,year,date,week);
portinit() ; /* init terminal modes */
signon() ;
driver() ;
portrst() ; /* undo any special modes */
}
/* end of mainline routine */
driver()
{
char linebuf[MAXLINE],
buf[128],
*bufptr, /* ptr to buf */
usercd[100], /* user record */
*userptr, /* ptr to usercd */
cmd[2];
int cnt,
ok_sw,
case_sw,
i,
num0,
num1,
num2;
cnt = 0;
ok_sw = TRUE;
bufptr = buf;
xpert = FALSE;
cmd[0] = '\0';
while (active)
{
stop_that = FALSE ; /* reset switch */
portsout(CRLF);
if (!xpert)
{
portsout("Commands: B,C,E,G,K,N,Q,R,S,W,X or ? ");
}
portsout("===> ");
portsin(cmd,1);
portsout(CRLF);
*cmd = toupper(*cmd) ;
switch (cmd[0])
{
case ('C'): /* Unix */
cmd_c();
break;
case ('E'): /* enter msg */
cmd_e();
break;
case ('G'): /* goodby */
cmd_g();
break;
case ('K'): /* kill msg */
cmd_k();
break;
case ('Q'): /* quick scan */
cmd_q();
break;
case ('R'): /* read msg */
cmd_r();
break;
case ('S'): /* scan msg */
cmd_s();
break;
case ('X'): /* expert toggle */
cmd_x();
break;
case ('N'): /* print new-user stuff */
cmd_p(NEWUSER);
break;
case ('W'): /* print welcome file */
cmd_p(WELCOME);
break;
case ('B'): /* print bulletins */
cmd_p(BULLETINS);
break;
case ('?'): /* help */
cmd_p(HELP);
break;
default:
break;
}
}
}
/* end of function */
cmd_g() /* good-by */
{
active = FALSE;
portsout("\r\nThanks for calling ");
portsout(w_fname) ;
portsout(CRLF) ;
sleep(5) ; /* for the Smartmodem */
portsout("+") ; /* get the modems attention */
portsout("+") ; /* get the modems attention */
portsout("+") ; /* get the modems attention */
sleep(15) ; /* for the Smartmodem */
gobble() ;
portsout("ATH") ; /* hang up the phone */
portsout(CRLF) ;
sleep(15) ; /* for the Smartmodem */
}
/* end of function */
cmd_c() /* go to the operating system level */
{
if ((inbuf=fopen(SYSTEM,"r")) == NULL)
{
portsout(CRLF) ;
portsout("Exiting to the operating system level!") ;
portsout(CRLF) ;
}
else
{
porttype(inbuf); /* type a file to port */
close(inbuf);
}
active = FALSE;
}
/* end of function */
cmd_e() /* enter a message */
{
int entering,
editing,
cnt1;
char msg[50],
l_cnt[3],
ans[2];
entering = editing = TRUE;
cnt1 = 0;
l_cnt[0] = '0'; /* init line count */
msg_text[0] = '\0'; /* init message text area */
portsout(CRLF);
portsout("This will be message # ");
portsout(h_next_msg);
portsout(CRLF);
portsout(" ____.____1____.____2\r\n");
portsout("Who is the message for ===> ");
portsin(msg_to,20);
portsout(CRLF);
portsout("What is the subject ===> ");
portsin(msg_subject,20);
portsout(CRLF);
portsout(CRLF) ;
portsout("A line can contain 40 characters, up to 20 lines.") ;
portsout(CRLF) ;
portsout("To end, enter a carriage return on an empty line.") ;
portsout(CRLF) ;
portsout(CRLF) ;
portsout(" .___.____1____.____2____.____3____.____4") ;
portsout(CRLF) ;
while (entering) /* get the text of the message */
{
linecnt(l_cnt); /* calc line count */
portsout(l_cnt); /* show line count */
portsout("> "); /* and prompt */
portsin(msg,40);
portsout(CRLF);
strcat(msg,"\n"); /* put a <lf> on each line */
if (strlen(msg) < 2) /* count cr too */
{
entering = FALSE; /* all done */
}
else
{
strcat(msg_text,msg); /* append each line to text */
}
if ((++cnt1) > 19) /* only allow 20 lines */
{
entering = FALSE; /* all done */
}
}
while (editing) /* save it, fix it, list it, or get out */
{
portsout(CRLF);
portsout("(S)ave, (L)ist, or (Q)uit") ;
portsout(CRLF);
portsout("(D)elete, (I)nsert, or (E)dit line ==> ") ;
portsin(ans,1); /* get a byte */
portsout(CRLF);
*ans = toupper(*ans) ;
switch (ans[0]) /* get 1 byte */
{
case ('S'): /* save message */
savemsg();
editing = FALSE; /* get out of while */
break;
case ('E'): /* edit message */
case ('I'): /* edit message */
case ('D'): /* edit message */
editmsg(*ans);
break;
case ('L'): /* list message */
listmsg();
break;
case ('Q'): /* get out w/out saving */
editing = FALSE; /* get out of while */
break;
default:
portsout(CRLF);
portsout("Shall we try that one again?\r\n");
break;
}
}
}
/* end of function */
linecnt(lcnt) /* 2 byte string of line numbers */
char *lcnt;
{
int icnt;
char xcnt[4];
icnt = atoi(lcnt);
if (++icnt < 10)
{
strcpy(lcnt,"0");
itoa(xcnt,icnt);
strcat(lcnt,xcnt);
}
else
{
itoa(xcnt,icnt);
strcpy(lcnt,xcnt);
}
return;
}
/*